#include "htaTracker.h"

htaTracker::htaTracker(){}

htaTracker::htaTracker(CvCapture* cap,int camIndex) {
	this->resetPose();		// reset pose
	_pCapture = cap;
	_pCapture = cvCaptureFromCAM(camIndex);

	_updateBGmodel = true;
	_useBGmodel = true;

	DebugLogger::infoPrint("Constructor -> webcam");
}

htaTracker::htaTracker(CvCapture* cap,const char* filename) {
	this->resetPose();
	_pCapture = cap;
	_pCapture = cvCaptureFromFile(filename);
	DebugLogger::infoPrint("Constructor -> AVI");
}

htaTracker::~htaTracker() {
	cvReleaseCapture(&_pCapture);
}

void htaTracker::resetPose() {
	_pose.x = 0;
	_pose.y = 0;
}

bool htaTracker::initTracker(CvCapture* cap,int camIndex) {
	DebugLogger::infoPrint("InitWebcamTracker");
	_pCapture = cap;
	_pCapture = cvCaptureFromCAM(camIndex);

	_updateBGmodel = true;
	_useBGmodel = true;
	//GaussianBGModel();
	return false;
}

bool htaTracker::initTracker(CvCapture* cap,const char* filename) {
	DebugLogger::infoPrint("InitAviTracker");
	return false;
}

void htaTracker::trackObject()
{
	_frame = cvQueryFrame(_pCapture);		// Get next frame from stream
	
	// use Gaussian BG model
	if(_useBGmodel){
		if(!_bgModel) {				// there is no model yet -> create one
			_bgModel = cvCreateGaussianBGModel(_frame);
		}
		else {		// update BG model
			cvUpdateBGStatModel(_frame,_bgModel,_updateBGmodel ? -1 : 0);
		}
	}
}